package com.ruoyi.web.controller.basedata;

import com.ruoyi.basedata.domain.TerminalType;
import com.ruoyi.basedata.service.ITerminalTypeService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 型号管理Controller
 * 
 * @author ruoyi
 * @date 2023-09-06
 */
@RestController
@RequestMapping("/basedata/terminaltype")
public class TerminalTypeController extends BaseController
{
    @Autowired
    private ITerminalTypeService terminalTypeService;

    /**
     * 查询型号管理列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:terminaltype:list')")
    @GetMapping("/list")
    public TableDataInfo list(TerminalType terminalType)
    {
        startPage();
        List<TerminalType> list = terminalTypeService.selectTerminalTypeList(terminalType);
        return getDataTable(list);
    }

    /**
     * 导出型号管理列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:terminaltype:export')")
    @Log(title = "型号管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TerminalType terminalType)
    {
        List<TerminalType> list = terminalTypeService.selectTerminalTypeList(terminalType);
        ExcelUtil<TerminalType> util = new ExcelUtil<TerminalType>(TerminalType.class);
        util.exportExcel(response, list, "型号管理数据");
    }

    /**
     * 获取型号管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('basedata:terminaltype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(terminalTypeService.selectTerminalTypeById(id));
    }

    /**
     * 新增型号管理
     */
    @PreAuthorize("@ss.hasPermi('basedata:terminaltype:add')")
    @Log(title = "型号管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TerminalType terminalType)
    {
        return toAjax(terminalTypeService.insertTerminalType(terminalType));
    }

    /**
     * 修改型号管理
     */
    @PreAuthorize("@ss.hasPermi('basedata:terminaltype:edit')")
    @Log(title = "型号管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TerminalType terminalType)
    {
        return toAjax(terminalTypeService.updateTerminalType(terminalType));
    }

    /**
     * 删除型号管理
     */
    @PreAuthorize("@ss.hasPermi('basedata:terminaltype:remove')")
    @Log(title = "型号管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(terminalTypeService.deleteTerminalTypeByIds(ids));
    }
}
